package com.share.utils;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class UserUtils {
    private static final ThreadLocal<Long> currentUser = new ThreadLocal<>();

    public static void set(Long userId) {
        log.info("写入用户:{} 线程ID:{}", userId, Thread.currentThread().getId());
        currentUser.set(userId);
    }

    public static Long get() {
        Long userId = currentUser.get();
        log.info("获得用户:{} 线程ID:{}", userId, Thread.currentThread().getId());
        return userId;
    }

    public static void remove() {
        currentUser.remove();
    }
}
